package com.qf.controller;

import com.qf.entity.Tree;
import com.qf.entity.User;
import com.qf.service.TreeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author chen
 * @version 1.0
 * @date 2019/10/24 16:54
 */
@Controller
public class TreeController {
    @Resource
    private TreeService treeService;
    @RequestMapping("/comment/getLoveTree")
    @ResponseBody
    public Map getLoveTree(HttpSession session){
        User user =(User) session.getAttribute("user");



        Tree tree = treeService.getLoveTree(1);
        Map map = new HashMap();
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String today = format.format(date);
        String lastsun = format.format(tree.getLastsun());
        String lastwater = format.format(tree.getLastwater());

        if (lastsun.compareTo(today)<0){
            map.put("sun", 0);
        }else {
            map.put("sun", 1);
        }

        if (lastwater.compareTo(today)<0){
            map.put("water", 0);
        }else {
            map.put("water", 1);
        }

        map.put("loveTree", tree);
        return map;
    }
}
